import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:visitor_scan_package/net/response/scan_result_data.dart';
import 'package:visitor_scan_package/utils/dotted_line.dart';

import '../viewmodel/scan_result_view_model.dart';

class ScanResultPage extends BaseStatefulMvvmWidget {
  final ScanResultData result;

  ScanResultPage(this.result);

  @override
  State<StatefulWidget> createState() => _ScanResultState();
}

class _ScanResultState
    extends BaseMvvmState<ScanResultViewModel, ScanResultPage> {
  @override
  Widget? buildLoadingContentView() {
    return ListView(
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Icon(
              Icons.check_circle_outline,
              color: Colors.green,
            ),
            Container(
              width: 10,
            ),
            CommonText('核销成功！', textSize: 18, fontWeight: FontWeight.bold)
          ],
        ).addToContainer(
            alignment: Alignment.center,
            margin: EdgeInsets.symmetric(horizontal: 46, vertical: 20),
            padding: EdgeInsets.symmetric(vertical: 20),
            decoration: BoxDecoration(
                borderRadius: 10.borderRadius,
                border: Border.all(color: Colors.green),
                color: Colors.green[100])),
        Container(
          height: 10,
        ),
        Container(
          height: 0.5,
          color: Colors.grey,
          width: double.infinity,
          margin: EdgeInsets.symmetric(horizontal: 10),
        ),
        IconTitleTextWidget(
          '来访时间:',
          height: 46,
          text: widget.result.intoDate ?? "",
          showArrow: false,
        ),
        dottedLine(),
        IconTitleTextWidget(
          '姓名:',
          height: 46,
          text: widget.result.visitorName ?? "",
          showArrow: false,
        ),
        dottedLine(),
        IconTitleTextWidget(
          '手机号:',
          height: 46,
          text: widget.result.telPhone ?? "",
          showArrow: false,
        ),
        dottedLine(),
        IconTitleTextWidget(
          '身份证号:',
          height: 46,
          text: widget.result.idCardNumber ?? "",
          showArrow: false,
        ),
        dottedLine(),
        IconTitleTextWidget(
          '来访事由:',
          height: 46,
          text: widget.result.visitReason == '2' ? "业务接待" : '家属探访',
          showArrow: false,
        ),
        dottedLine(),
        IconTitleTextWidget(
          '来访人数:',
          height: 46,
          text: widget.result.visitNumber.toString(),
          showArrow: false,
        ),
        dottedLine(),
        IconTitleTextWidget(
          '被访人姓名:',
          height: 46,
          text: widget.result.intervieweeName ?? "",
          showArrow: false,
        ),
        dottedLine(),
        IconTitleTextWidget(
          '车牌:',
          height: 46,
          text: widget.result.carNo ?? "",
          showArrow: false,
        ),
        dottedLine(),
        Container(
          height: 20,
        )
      ],
    );
  }

  Widget dottedLine() {
    return const DottedLine(
      height: 0.5,
    ).addToContainer(
        width: double.infinity,
        margin: const EdgeInsets.symmetric(horizontal: 10));
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('核销结果'),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  ScanResultViewModel createViewModel() {
    return ScanResultViewModel(context, widget.result);
  }

  @override
  void onRetryClick() {}
}
